// Text Scene Node
// (c) jimon game studio

#ifndef JEH_CTEXTSCENENODE
#define JEH_CTEXTSCENENODE

#include "ITextSceneNode.h"
#include "ISceneManager.h"
#include "IFontManager.h"

namespace je
{
	namespace scene
	{
		//! Text Scene Node
		class CTextSceneNode:public je::scene::ITextSceneNode
		{
		private:
			//! Current Scene Manager
			scene::ISceneManager * CurrentSceneManager;

			//! Current Text
			jeStringd CurrentText;

			//! Font Resource
			media::jeFontResource * CurrentFontResource;
			media::jeSharedTexture * CurrentSharedTexture;

			//! Render Operation
			video::jeRenderOperation_Draw * TextRenderOperation; 

			//! Text Options
			TextOptions CurrentTextOptions;

			//! Position
			jeMatrix4f TextMatrix;
			jeMatrix4f TextAbsoluteModelMatrix;
			jeVector3df TextSize;
			jeVector3df TextCorrectionSize;
		public:
			//! Constructor
			CTextSceneNode(video::IRender * Render,scene::ISceneManager * SceneManager);

			//! Destructor
			~CTextSceneNode();

			//! Set Text
			void SetText(const jeStringd & Text);

			//! Get Text
			const jeStringd & GetText();
			
			//! Get Text Size in pixels
			jeVector2di GetTextSize()
			{
				if(CurrentFontResource)
					return CurrentFontResource->GetFont()->CalculateTextSize(CurrentText);
				else
					return jeVector2di(0);
			}

			//! Set Text Options
			void SetTextOptions(const TextOptions & Options)
			{
				CurrentTextOptions = Options;
				NeedToRebuildMatrix = true;
				SetText(GetText());
			}

			//! Get Text Options
			const TextOptions & GetTextOptions()
			{
				return CurrentTextOptions;
			}

			//! Set Font Resource
			void SetFontResource(media::jeFontResource * FontResource);

			//! Get Font Resource
			media::jeFontResource * GetFontResource();

			//! Set Material Resource
			void SetMaterialResource(media::jeMaterialResource * MaterialResource,u1 UseUniqueMaterial = true,u1 UseUniqueTextures = true,u1 UseUniqueShader = true);

			//! On Update
			void OnUpdate();

			//! On Render
			void OnRender();

			//! On Visibility Culling
			void OnVisibilityCulling();

			//! Rebuild Transformations
			void RebuildTransformations();

			//! Build Absolute Model Matrix
			void BuildAbsoluteModelMatrix(const jeMatrix4f & ParentMatrix,const jeVector3df & ParentScale,u1 Changed);

			//! Serialize
			void Serialize(core::ISerializeStream * SerializeStream);

			//! Get Node Type Name
			jeStringc GetNodeTypeName()
			{
				return jeStringc("TextSceneNode");
			}
		};
	}
}

#endif
